//
//  ZMPresentationController.swift
//  ZMWB
//
//  Created by 朱敏 on 2017/9/26.
//  Copyright © 2017年 朱敏. All rights reserved.
//

import UIKit

class ZMPresentationController: UIPresentationController {
    
    // 保存菜单的尺寸
    var presentFrame = CGRect.zero
    
    override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) {
        super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
    }
    
    // 用于布局转场动画弹出的控件
    override func containerViewWillLayoutSubviews() {
        presentedView?.frame = presentFrame
        
        //添加蒙板
        containerView?.insertSubview(coverButton, at: 0)
        coverButton.addTarget(self, action: #selector(coverBtnClick), for: UIControlEvents.touchUpInside)
    }

    // MARK: - 内部控制方法
    @objc private func coverBtnClick() {
        ZMLog(message: "");
        // 让菜单消失
        presentedViewController.dismiss(animated: true, completion: nil)
    }
    
    // MARK: - 懒加载
    private var coverButton: UIButton = {
        let btn = UIButton()
        btn.frame = UIScreen.main.bounds
        return btn
    }()
}
